// member-info
const { BaseBehavior, COMPONENT_OPTIONS } = require('../../mixins/component');
const { getUserInfo } = require('../../common/platform');

Component({
    behaviors: [BaseBehavior],
    options: {
        ...COMPONENT_OPTIONS,
    },
    properties: {
        memberInfo: {
            type: Object,
            value: {},
        },
    },
    data: {
        canIUseGetUserProfile: false,
    },
    lifetimes: {
        attached: function () {
            // 在组件实例进入页面节点树时执行
            if (wx.getUserProfile) {
                this.setData({
                    canIUseGetUserProfile: true,
                })
            }
        },
        detached: function () {
            // 在组件实例被从页面节点树移除时执行
        },
    },
    methods: {
        async getUserProfile(e) {
            const userInfo = await getUserInfo();
            console.log('用户信息为：', userInfo);
            this.triggerEvent('update', userInfo);
        },
        async getUserInfo(e) {
            console.log('用户信息为：', e.detail.userInfo);
            // await userUpdate(e.detail);
            this.triggerEvent('update', e.detail.userInfo);
        },
        getUserPhoneNumber(e) {
            const { iv, encryptedData } = e.detail;
            this.triggerEvent('mobile', { iv, encryptedData });
        },
    }
})